﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace fanfu.Common
{
    /// <summary>
    /// 注释器
    /// <remarks>在SQL语句后添加对此语句的一些说明,帮助分析和优化程序</remarks>
    /// </summary>
    public class Interpreter
    {
        /// <summary>
        /// 注释的添加作者
        /// </summary>
        public enum Author
        {
            /// <summary>
            /// 樊甫
            /// </summary>
            fanfu = 1
        }

        /// <summary>
        /// 此项目的名称
        /// </summary>
        public static readonly string PlatName = "樊甫的网站后台";

        /// <summary>
        /// 在SQL语句后面追加注释
        /// </summary>
        /// <param name="sql">需追加注释的SQL语句</param>
        /// <param name="plat">此SQL语句操作的项目</param>
        /// <param name="author">作者</param>
        /// <param name="forUse">SQL的功能描述</param>
        /// <param name="fileName">SQL所在的文件名</param>
        /// <param name="funName">SQL所在的方法名</param>
        /// <returns>添加注释后的SQL</returns>
        public static string AppendComment(string sql, string plat, Author author, string forUse, string fileName, string funName)
        {
            if (string.IsNullOrEmpty(sql))
                throw new ArgumentNullException("sql参数为null或空字符串");
            if (string.IsNullOrEmpty(plat))
                throw new ArgumentNullException("plat参数为null或空字符串");
            if (string.IsNullOrEmpty(forUse))
                throw new ArgumentNullException("forUse参数为null或空字符串");
            if (string.IsNullOrEmpty(fileName))
                throw new ArgumentNullException("fileName参数为null或空字符串");
            if (string.IsNullOrEmpty(funName))
                throw new ArgumentNullException("funName参数为null或空字符串");

            string sqlWithComment = string.Format(@"{0}
                --Flat:{1}/Author:{2}/For:{3}/File:{4}/Fun:{5}", sql, plat, author.ToString(), forUse, fileName, funName);

            return sqlWithComment;
        }

        /// <summary>
        /// 在SQL语句后面追加注释
        /// </summary>
        /// <param name="sql">需追加注释的SQL语句</param>
        /// <param name="author">作者</param>
        /// <param name="forUse">SQL的功能描述</param>
        /// <param name="fileName">SQL所在的文件名</param>
        /// <param name="funName">SQL所在的方法名</param>
        /// <returns>添加注释后的SQL</returns>
        public static string AppendComment(string sql, Author author, string forUse, string fileName, string funName)
        {
            return AppendComment(sql, PlatName, author, forUse, fileName, funName);
        }
    }
}
